package com.lotus.lqmp.service.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.lotus.lqmp.base.biz.bean.PageQuery;
import com.lotus.lqmp.service.controller.vo.req.DeliverablesQueryReq;
import com.lotus.platform.common.model.enums.DeletedStatusEnum;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import com.lotus.lqmp.service.dao.DeliverablesTemplateConfigMapper;
import com.lotus.lqmp.service.dao.entity.DeliverablesTemplateConfigDo;
import com.lotus.lqmp.service.service.DeliverablesTemplateConfigService;
import com.lotus.platform.common.biz.impl.BaseBiz;

/**
 * 交付物模板配置表Service业务层处理
 *
 * @author Shiheng.Liu1
 * @date 2022-03-29
 */
@Service
public class DeliverablesTemplateConfigServiceImpl extends BaseBiz<DeliverablesTemplateConfigMapper, DeliverablesTemplateConfigDo>  implements DeliverablesTemplateConfigService{
    @Autowired
    private DeliverablesTemplateConfigMapper deliverablesTemplateConfigMapper;

    @Override
    public DeliverablesTemplateConfigDo getExistByName(String deliverablesName) {
        QueryWrapper<DeliverablesTemplateConfigDo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted_status", String.valueOf(DeletedStatusEnum.normal.getCode()));
        queryWrapper.eq("deliverables_name", deliverablesName);
        return deliverablesTemplateConfigMapper.selectOne(queryWrapper);
    }

    @Override
    public DeliverablesTemplateConfigDo getByExistById(Long id) {
        QueryWrapper<DeliverablesTemplateConfigDo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted_status", String.valueOf(DeletedStatusEnum.normal.getCode()));
        queryWrapper.eq("id", id);
        return deliverablesTemplateConfigMapper.selectOne(queryWrapper);
    }

    @Override
    public Page<DeliverablesTemplateConfigDo> queryForPage(PageQuery<DeliverablesQueryReq> queryInfo) {
        QueryWrapper<DeliverablesTemplateConfigDo> queryWrapper = new QueryWrapper<>();
        queryWrapper.eq("deleted_status", String.valueOf(DeletedStatusEnum.normal.getCode()));
        if (StringUtils.isNoneBlank(queryInfo.getQueryInfo().getDeliverablesName())) {
            queryWrapper.eq("deliverables_name", queryInfo.getQueryInfo().getDeliverablesName());
        }
        Page<DeliverablesTemplateConfigDo> page = new Page<>(queryInfo.getPageNum(), queryInfo.getPageSize());
        return deliverablesTemplateConfigMapper.selectPage(page, queryWrapper);
    }
}
